home *** CD-ROM | disk | FTP | other *** search
- /* This version is for Turbo C 2.0
- *
- * Compilation syntax:
- * tcc -w -G go.c
- */
-
-
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <dir.h>
- #include <string.h>
-
- #ifndef TRUE
- #define TRUE 1
- #define FALSE 0
- #endif
-
- extern unsigned _stklen = 0x1000;
-
- int file_search = TRUE;
- int dir_search = TRUE;
- int orig_drive;
- char *orig_dir;
- int search_drive;
- char *search_string;
- char *dir_search_string;
- int dir_search_length;
- char *file_search_string;
- int reset_drive = FALSE;
- int reset_dir = FALSE;
-
- void do_resets(void);
- void help(void);
- void test_dir(void);
-
- void main(int argc, char **argv)
- {
- unsigned new_drive;
-
- atexit(do_resets);
-
- if (argc < 2 || argc > 3)
- help();
-
- orig_drive = getdisk();
- orig_dir = getcwd(NULL,MAXDIR);
-
- if (argc == 3)
- if (strcmpi(argv[2],"-F") == 0 || strcmpi(argv[2],"/F") == 0)
- dir_search = FALSE;
- else
- help();
-
- search_string = strdup(strupr(argv[1]));
- if(search_string[1] == ':')
- {
- new_drive = search_string[0] - 'A';
- setdisk(new_drive);
- reset_drive = TRUE;
- search_string += 2;
- }
-
- if (search_string[0] == '\\')
- {
- search_string++;
- file_search = FALSE;
- }
-
- if(strchr(search_string,'?') || strchr(search_string,'*'))
- dir_search = FALSE;
-
- if (dir_search)
- {
- dir_search_string = search_string;
- dir_search_length = strlen(dir_search_string);
- }
-
- if (file_search)
- {
- file_search_string = malloc(strlen(search_string)+3);
- strcpy(file_search_string, search_string);
- if(! strchr(file_search_string, '.' ))
- strcat(file_search_string, ".*");
- }
-
- if (dir_search | file_search)
- {
- chdir("\\");
- test_dir();
- reset_dir = TRUE;
- exit(0);
- }
- else
- help();
- }
-
- void help(void)
- {
- puts("\nGO moves you quickly from one subdirectory to another.");
- puts("Syntax:");
- puts(" GO [d:][\\]pathname [-F]");
- puts(" the pathname can be either the name of a directory or");
- puts(" the name of a file. It may contain wild cards.\n");
- puts(" If 'd:' is included, drive 'd:' will be used instead");
- puts(" of the current drive.\n");
- puts(" If '\\' is included at the beginning of the pathname,");
- puts(" only subdirectory names will be searched.\n");
- puts(" If '-F' or /F' is included, or if the pathname includes");
- puts(" wild card sybmols, only file names will be searched\n");
- puts(" Normally, both file names and subdirectory names are");
- puts(" searched to match the specified pathname.");
- exit(0);
- }
-
- void do_resets(void)
- {
-
-
- if(reset_dir)
- {
- chdir(orig_dir);
- puts (" Requested subdirectory not found\a");
- }
- else
- {
- fputs(" New Directory: ",stdout);
- puts (getcwd(NULL,MAXDIR));
- }
-
- if(reset_drive)
- setdisk(orig_drive);
- }
-
- void test_dir(void)
- {
- char *current_dir, *cptr;
- int i;
- struct ffblk find_buffer;
-
- current_dir = getcwd(NULL,MAXDIR);
- if(dir_search && ((i = strlen(current_dir)) >= dir_search_length))
- {
- cptr = current_dir + (i - dir_search_length);
- if (!strcmp(cptr,search_string))
- exit(0);
- }
-
- if(file_search)
- {
- if(!findfirst(file_search_string, &find_buffer, 0))
- exit(0);
- }
-
- findfirst("*.*", &find_buffer, FA_DIREC);
- if(find_buffer.ff_attrib == FA_DIREC && find_buffer.ff_name[0] != '.')
- {
- chdir(find_buffer.ff_name);
- test_dir();
- chdir(current_dir);
- }
-
- while (! findnext(&find_buffer))
- if(find_buffer.ff_attrib == FA_DIREC && find_buffer.ff_name[0] != '.')
- {
- chdir(find_buffer.ff_name);
- test_dir();
- chdir(current_dir);
- }
-
- free(current_dir);
- }